package com.cn.wanxi.service.impl;

import com.cn.wanxi.dto.HomeDTO;
import com.cn.wanxi.model.*;
import com.cn.wanxi.service.*;

import java.util.List;

public class HomeServiceImpl implements IHomeService {
    @Override
    public ResultModel getFrontHome() {
        ResultModel resultModel = new ResultModel();
        try {
            HomeDTO homeDTO = new HomeDTO();

            homeDTO.setNewsModelList(getNewsModelList());
            homeDTO.setProductModelList(getProductModelList());
            resultModel.setCode(200);

            resultModel.setObject(homeDTO);
        } catch (Exception e) {
            resultModel.setResult(e.getLocalizedMessage());
            resultModel.setCode(400);
        }

        return resultModel;
    }


    private List<NewsModel> getNewsModelList() {
        NewsService newsService = new NewsService();
        List<NewsModel> newsModelList = newsService.getNewsModelListForHomeFromIO();
        return newsModelList;
    }

    private List<ProductModel> getProductModelList() {
        ProductService productService = new ProductService();
        List<ProductModel> productModelList = productService.getProductListForHomeFromIO();
        return productModelList;
    }
}
